<?php
if (isset($lote_data)) :

    if ($lote_data->TIPO == 'DI' || $lote_data->RETIRADO == 'S') {
        redirect('');
    }

    add_js('scripts/detail-lotes', 'footer', 20);
    add_js('plugins/jquery.onTickerDown', 'footer', 12);

    $comitentes = array();

    $c_data = $this->db->get('comitentes')->result();
    foreach ($c_data as $key => $comitente) {
        $comitentes [$comitente->ID] = $comitente;
    }
    $lote = $lote_data;
    $this->db->order_by('ID', 'DESC');
    $rw = $this->db->get_where('lotes_plus_time', array(
                'LOTE_ID' => $lote->ID
            ))->row();
    $is_show_lance = $dt_orig = compare_date_max(date('Y-m-d H:i:s'), $lote->FECHAMENTO);
    $date_end = $lote->FECHAMENTO;

    if ($rw && compare_date_max(date('Y-m-d H:i:s'), $rw->DATA) && intval(strtotime($lote->FECHAMENTO)) < intval(strtotime($rw->DATA))) {
        $is_show_lance = compare_date_max(date('Y-m-d H:i:s'), $rw->DATA);
        $date_end = $rw->DATA;
    }
    $array_lotes_page = array();

    if (count($array_lotes) > 0) {
        foreach ($array_lotes as $key => $rlote) {
            $array_lotes_page [] = $rlote->ID;
        }
    }

    echo form_hidden('lote->LEILAO_ID', $lote->lote->LEILAO_ID);
    echo form_hidden('usuario_id', $this->session->userdata('id'));
    ?>

    <!-- headline -->


    <!-- SIDEBAR -->
    <!-- BOX-DATA -->



    <?php
endif;
if ($info_habilitacao) {
    echo $info_habilitacao;
}
?>
<div class="col-md-3 col-sm-5 sidebar-cat sidebar-cat-resp">
    <div class="text-categ">
        <span class="header-categoria">CATEGORIAS</span>
    </div>
    <?php if (count($count_categories) > 0): ?>
        <ul class="filter-categorias filter">
            <?php foreach ($count_categories as $categorie): ?>
                <li class="item"><a class="item-header" href="javascript:void(0)"> <i
                            class="ico-float"><img
                                src="/public/images/icones/<?php echo $categorie->SLUG ?>.png"></i>

                        <span class="item-label"><?php echo $categorie->NAME ?> <em
                                class="total-by-categorie"><?php echo $categorie->TOTAL; ?></em></span>
                    </a>
                    <div class="clearfix"></div>
                    <ul class="filter-box">
                        <?php if (count($categorie->SUB_CATEGORIES) > 0): ?>

                            <li class="categoria-filter"><span>Categoria</span></li> 
                            <div class="box-checkbox">
                                <?php foreach ($categorie->SUB_CATEGORIES as $row): ?>
                                    <li class="categoria-filter-item">
                                        <div class="checkbox">
                                            <label> <input data-trigger
                                                           url="<?php echo site_url('lotes/' . $categorie->SLUG . '/' . $row->SLUG) ?>"
                                                           type="checkbox"> <?php echo $row->NAME; ?>
                                            </label>
                                        </div>
                                    </li>
                                </div>
                            <?php endforeach; ?>
                        <?php endif; ?>


                    </ul></li>
            <?php endforeach; ?>
        </ul>
    <?php endif; ?>
    <?php if (count($count_estados) > 0): ?>
        <?php $uf_total = 0; ?>
        <div class="filter-box">
            <div class="categoria-filter">
                <span>Estados</span>
            </div>
            <div class="box-checkbox">
                <ul class="menu-filter-estados">
                    <?php foreach ($count_estados as $row): ?>
                        <li><a
                                href="<?php echo site_url('lotes/todos/todos/localizados-em-' . $row->UF); ?>"><?php echo $row->NOME; ?> (<?php echo $row->TOTAL; ?>)</a></li>
                            <?php $uf_total+= $row->TOTAL; ?>
                        <?php endforeach; ?>
                </ul>
            </div>
        </div>        
        <div class="box-total-lotes-all-country">
            <span>TOTAL DE LOTES EM LEILÃO </span> <span class="num-all-country"><?php echo $uf_total; ?></span>
        </div> 
    <?php endif; ?>
</div>
<!-- SIDEBAR -->
<!-- BOX-DATA -->
<div class="col-md-9 list-cat-page page-detail-lote-detalhes margin-top-20">


    <div class="col-md-12 b-header-lote-detail">
        <span class="num-lote-label-detail">Lote <?php echo $lote->NUM_LOTE; ?></span>
        <span class="title-comitente-leilao-lote-detail"> Leilão : <?php echo $lote->CLIENTE; ?> - 11H </span>
        <?php if (count($paginate) > 1): ?>
            <?php $index = array_search($lote->CODLOTE, $paginate); ?>
            <?php $prev = abs($index - 1); ?>
            <?php $next = abs($index + 1); ?>
            <?php $next = $next > (count($paginate) - 1 ) ? count($paginate) - 1 : $next; ?>
            <?php if ($prev < $index) { ?>
                <a
                    href="<?php echo site_url('detalhes-lote/' . $paginate[$prev] . '/' . $lote->LEILAO_ID); ?>"
                    class="lote-detail-prev"><i clas="fa fa-backward"></i> Anterior</a>
                <?php } ?>
                <?php if ($index < $next) { ?>

                <a
                    href="<?php echo site_url('detalhes-lote/' . $paginate[$next] . '/' . $lote->LEILAO_ID); ?>"
                    class="lote-detail-next"><i clas="fa fa-forward"></i> Próximo</a>
                <?php } ?>
            <?php endif; ?>
        <a show-message-login href="javascript:void()" class="text-seguir-ofertas">SEGUIR A OFERTA <i class="fa fa-star-o"></i></a>
        <a class="pull-right link-leiloes-prevAll" href="/"><i class="fa fa-backward"></i>&nbsp;&nbsp;VOLTA PARA TODAS AS CATEGORIAS</a>
    </div>

    <div id="box-geral-lote">
        <div class="info-lote-detalhe">
            <div class="logo-lote">
                <img
                    src="/public/images/comitentes/<?php echo!empty($lote->LOGO) ? $lote->LOGO : (!empty($lote->IMAGEM) ? $lote->IMAGEM : 'no_image.jpg' ); ?>"
                    width="50px" />
            </div>
            <div class="descricao-lote">

                <strong><?php echo $lote->DESCRICAO; ?></strong><br />
                <?php echo $lote->SUB_DESCRICAO; ?><br />
                Local: <?php echo $lote->CIDADE_LOTE . ' / ' . $lote->UF; ?>

            </div>
        </div>
        <?php $files = explodeImages($lote->IMAGENS); ?>
        <div class="img-lote">
            <a href="/public/images/lotes/<?php echo $files['0']; ?>"
               class="jqzoom" title="<?php echo $lote->DESCRICAO; ?>" rel='gal1'> <img
                    id="img_1"
                    src="/public/images/lotes/smalls/<?php echo $files['0']; ?>" />
            </a>


        </div>
        <?php // check if exists link movie  ?>
        <?php if (filter_var($lote->LINK, FILTER_VALIDATE_URL)): ?>
            <div class="link-video">
                <a class="text-link-video" href="<?php echo $lote->LINK; ?>">Assista
                    ao video <img src="/public/images/btn_video.png" />
                </a>
            </div>
        <?php endif; ?>
        <div id="galeria" class="box-gallery-items">
            <!-- thumbs loops -->
            <?php if (count($files) > 0): ?>
                <?php foreach ($files as $key => $thumb): ?>
                    <?php $is_active = $key == 0 ? 'zoomThumbActive' : ''; ?>
                    <a class="<?php echo $is_active; ?>"
                       href="javascript:void(0)"
                       rel="{gallery: 'gal1', smallimage: '/public/images/lotes/smalls/<?php echo $thumb; ?>',
                       largeimage: '/public/images/lotes/<?php echo $thumb; ?>'}">
                        <img id="img_<?php echo $key + 1; ?>"
                             src="/public/images/lotes/thumbs/<?php echo $thumb; ?>" />
                    </a>
                <?php endforeach; ?>
            <?php endif; ?>

        </div>
        <div id="box-maxlive-geral">
            <div id="box-btn-maxlive">
                <div class="link-text-maxlive">
                    <span><a href="#">CLIQUE PARA EFETUAR SEU LANCE E ACOMPANHAR</a><br /></span>
                    <a href="#">MULTIPLOS LOTES SIMULTANEOS EM TEMPO REAL</a>
                </div>
                <div class="bg-btn-maxlive">
                    <a openPopup
                       href="<?php echo site_url('maxlive-' . $lote->LEILAO_ID . '.html') ?>"><span
                            class="text-maxlive">MAXLIVE</span></a>
                </div>
            </div>
            <div>
                <div class="info-geral-lote">
                    <p>INFORMACOES GERAIS DO LOTE</p>
                </div>
                <div class="desc-lote">
                    <p>
                        <span class="text-red-desc">Comitente:</span><span
                            class="text-black-desc"><?php
                                $comitente_name = $lote->CLIENTE;
                                if ($lote->TIPO == 'CO' && $lote->COMITENTE_ID > 0 && isset($comitentes [$lote->COMITENTE_ID])) {

                                    $comitente_name = $comitentes [$lote->COMITENTE_ID]->RAZAO;
                                }
                                echo $comitente_name;
                                ?></span>
                    </p>
                    <p class="pull-left">
                        <span class="text-red-desc">Horário:</span><span
                            class="text-black-desc"><?php echo substr(extract_time($lote->FECHAMENTO), 0, 5); ?></span>
                    </p>
                    <div class="pull-left padding-left-15">
                        <span class="text-red-desc">Data de abertura:</span><span
                            class="text-black-desc"><?php echo extract_data($lote->ABERTURA, '/'); ?></span>
                        
                    </div>
                    <div class="clearfix"></div>
                    <div>
                        <span class="text-red-desc">Lance Inicial:</span><span
                            class="text-black-desc">R$ <?php echo number_format($lote->LANCE_INICIAL, 2, ',', '.'); ?></span>
                       
                    </div>
                     <div class="clearfix"></div><br/>
                </div>
                <div class="box-container-info-extra-lote">
                    <p>
                        <span class="info-text-regras">Visitacao:</span><span
                            class="info-text-regras2"><?php echo $lote->INFO_VISITACAO; ?></span>
                    </p>
                    <p>
                        <span class="info-text-regras">Retirada:</span><span
                            class="info-text-regras2"><?php echo $lote->INFO_RETIRADA; ?></span>
                    </p>
                    <p>
                        <span class="info-text-regras">Informações extra:</span><span
                            class="info-text-regras2"></span>
                    </p>
                    <p class="text-acomp-lance"><?php echo $lote->INFO; ?></p>
                </div>
                <div class="info-geral-lote">
                    <p>DESCRICAO DETALHADA</p>
                </div>
                <div class="desc-itens">
                    <p><?php echo $lote->DESCRICAO_DETALHADA; ?></p>
                </div>
                <div class="cond-gerais-lote">
                    <p class="text-cond-gerais">Condicoes Gerais</p>
                </div>
                <div class="desc-itens"></div>
                <div lote-id="<?php echo $lote->CODLOTE; ?>"
                     class="box-atualize-history"></div>

            </div>
        </div>
    </div>

    <div id="box-painel-geral" box-painel-lote-info-item data-lote-id="<?php echo $lote->CODLOTE; ?>"
         data-le-id="<?php echo $lote->LEILAO_ID; ?>">
        <div id="box-painel">
            <div class="barra-painel-lance">
                <div class="box-top-painel">
                    <span class="text-painel-lance">PAINEL DE LANCE</span>
                    <div class="btn-maxlive-peq">
                        <a openPopup 
                           href="<?php echo site_url('maxlive-' . $lote->LEILAO_ID . '.html') ?>"
                           class="space-text-maxlive">MAXLIVE</a>
                    </div>
                </div>
                <div>
                    <div class="time-count lote-<?php echo $lote->CODLOTE; ?>"
                         data-count="<?php echo $lote->FECHAMENTO; ?>"></div>

                    <span class="label-group-info">G1</span>
                    <p class="text-fecha-dias">
                        ENCERRAMENTO:<span class="text-periodo-dias"><?php echo auto_format_data($lote->FECHAMENTO, '-', '/'); ?></span>
                    </p>
                </div>
                <div class="box-lance-atual-text">
                    <span class="lance-atual-black">LANCE ATUAL</span>
                    <?php $lance_atual = $lote->LAST_LANCE == NULL ? $lote->LANCE_INICIAL : $lote->LAST_LANCE; ?>
                    <span class="text-valor-atual"><?php echo 'R$ <span class="label-lance-ganhador">' . number_format($lance_atual, 2, ',', '.') . '</span>'; ?></span>
                </div>
                <div class="box-lance-atual-text">
                    <span class="lance-atual-cinza">GANHADOR ATUAL:</span> <span
                        class="text-name-ganhador label-ganhador"><?php echo $login = $lote->LANCE_TIPO == 'A' ? $lote->LOGIN . '(A)' : $lote->LOGIN; ?></span>
                </div>
                <div>
                    <p class="text-incr">
                        <span>INCREMENTO:</span><span class="text-incr-valor">R$ <span class="incremento-price"><?php echo number_format($lote->INCREMENTO, 2, ',', '.'); ?></span></span>
                        <span data-auto-lance="<?php echo $lote->CODLOTE; ?>"></span>
                </div>
                <div class="box-lance-atual-text yellow-claro">
                    <span class="lance-atual-black yellow-esc">PROXIMA OFERTA</span>
                    <div class="box-info-price">
                        <?php $price_next_oferta = $lote->INCREMENTO + $lance_atual; ?>
                        <span class="valor-yellow">R$ <span
                                class="next-price" data-next-price-id="<?php echo $lote->CODLOTE; ?>"><?php echo number_format($price_next_oferta, 2, ',', '.'); ?></span></span>
                    </div>        

                    <div title="<?php echo lang_system('title_info_lance_auto'); ?>" class="lance-automatic-box">
                        R$ <span class="lance-automatic-value"></span>
                    </div>        
                </div>
            </div>
            <?php if (is_null($lote->VENDIDO)): ?>
                <div class="lance_auto">
                    <?php $has_permission_auto_lance = 'show-message-login'; ?>
                    <?php if (userData()->id > 0 && (userData()->group == 'member') && isEnabled(userData()->id, $lote->LEILAO_ID) && isUnlocked(userData()->id, $lote->LEILAO_ID)): ?>
                        <?php $has_permission_auto_lance = ''; ?>
                    <?php endif; ?>
                    <?php if (userData()->id > 0 && (userData()->group == 'member') && (!isEnabled(userData()->id, $lote->LEILAO_ID) || !isUnlocked(userData()->id, $lote->LEILAO_ID))): ?>
                        <?php $has_permission_auto_lance = 'show-message-user-block'; ?>
                    <?php endif; ?>

                    <span class="text-auto">LANCE AUTOMATICO</span><br /> <span
                        class="btn-ativar"> 
                        <span auto-id="<?php echo $lote->CODLOTE; ?>" href="#" class="btn-lance-aut <?php echo isAutoLance(userData()->id, $lote->CODLOTE) ? 'on' : ''; ?>">A</span>
                    </span> <span class="text-off ">OFF</span>
                    </p>
                </div>


                <div class="btn-efetuar-lances" >
                    <div class="blocked-lance <?php echo isAutoLance(userData()->id, $lote->CODLOTE) ? '' : 'hide'; ?>">Lance Automatico</div> 

                    <?php $has_permission_auto_lance = 'show-message-login'; ?>
                    <?php if (userData()->id > 0 && (userData()->group == 'member') && isEnabled(userData()->id, $lote->LEILAO_ID) && isUnlocked(userData()->id, $lote->LEILAO_ID)): ?>
                        <?php $has_permission_auto_lance = ''; ?>
                    <?php endif; ?>
                    <?php if (userData()->id > 0 && (userData()->group == 'member') && (!isEnabled(userData()->id, $lote->LEILAO_ID) || !isUnlocked(userData()->id, $lote->LEILAO_ID))): ?>
                        <?php $has_permission_auto_lance = 'show-message-user-block'; ?>
                    <?php endif; ?>
                    <?php
                    $bid_click = $bid_permission = 'show-message-login';
                    if (userData()->id > 0 && (userData()->group == 'user' || userData()->group == 'admin' )) {
                        $bid_permission = 'no-lance-user';
                    }
                    if (userData()->id > 0 && (userData()->group == 'member') && isEnabled(userData()->id, $lote->LEILAO_ID)) {

                        $bid_permission = '';
                        $bid_click = ' bid-click';
                    }
                    ?>

                    <a href="#" <?php echo $bid_permission; ?> bid-id="<?php echo $lote->CODLOTE; ?>" class="btn-lances <?php echo $bid_click; ?>" ival="1">+1X</a> 
                    <a href="#" <?php echo $bid_permission; ?> bid-id="<?php echo $lote->CODLOTE; ?>" class="btn-lances <?php echo $bid_click; ?>" ival="2">+2X</a> 
                    <a href="#"  <?php echo $bid_permission; ?> bid-id="<?php echo $lote->CODLOTE; ?>" class="btn-lances <?php echo $bid_click; ?>" ival="5">+5X</a>
                    <a  <?php echo $bid_permission; ?> close-id="<?php echo $lote->CODLOTE; ?>" href="#" class="btn-lances2" resetBids>Minimo<br />VOLTAR
                    </a>
                    <?php // user is loggedin   ?>
                    <?php if (userData()->id === 0): ?>
                        <a href="<?php echo site_url(BASE_URL_USER . '/login' . (uri_string() != '' ? '?r=' . uri_string() : '')); ?>"
                           class="btn-login-lances">LOGIN</a>
                       <?php endif; ?>
                       <?php // users if blocked   ?>
                       <?php if (userData()->id > 0 && (userData()->group == 'user' || userData()->group == 'admin' )): ?>
                        <a no-lance-user leilao-id="<?php echo $lote->LEILAO_ID; ?>"
                           lance-lote-id="<?php echo $lote->CODLOTE; ?>" href="#"
                           class="btn-login-lances">BLOCK</a>
                       <?php endif; ?>
                       <?php // users if habilitation  ?>
                       <?php if (userData()->id > 0 && (userData()->group == 'member') && !isEnabled(userData()->id, $lote->LEILAO_ID)): ?>
                        <a role="previewCondicoes"
                           l-id="<?php echo $lote->LEILAO_ID; ?>"
                           u-id="<?php echo userData()->id; ?>" href="#"
                           class="btn-login-lances">HABIL.</a>
                       <?php endif; ?>
                       <?php // users if blocked  ?>
                       <?php if (userData()->id > 0 && (userData()->group == 'member') && isEnabled(userData()->id, $lote->LEILAO_ID) && !isUnlocked(userData()->id, $lote->LEILAO_ID)): ?>
                        <a has-habilitacao   u-id="<?php echo userData()->id; ?>" l-id="<?php echo $lote->LEILAO_ID; ?>"
                           lance-lote-id="<?php echo $lote->CODLOTE; ?>"
                           href="#" class="btn-login-lances">HABIL.</a>
                       <?php endif; ?>
                       <?php // users if enabled for lance  ?>
                       <?php if (userData()->id > 0 && (userData()->group == 'member') && isEnabled(userData()->id, $lote->LEILAO_ID) && isUnlocked(userData()->id, $lote->LEILAO_ID)): ?>
                        <a addLance leilao-id="<?php echo $lote->LEILAO_ID; ?>"
                           lance-lote-id="<?php echo $lote->CODLOTE; ?>"
                           href="#" class="btn-login-lances"><span class="loading-button"></span>
                            <span class="button-lance-label">LANCE</span></a>
                    <?php endif; ?>

                </div>

            <?php else: ?>
                <?php $message = '<div class="label label-danger label-lote-closed">LOTE VENDIDO</div>'; ?>
                <?php if ($lote->CONDICIONAL == 'S') { ?>
                    <?php $message = '<div class="label label-danger label-lote-closed">LOTE VENDIDO - CONDICIONAL</div>'; ?>
                <?php } ?>
                <?php echo $message; ?>
            <?php endif; ?>
            <div class="box-estatisticas-geral2">
                <span class="box-estatisticas space-estatisticas">Visitas</span> <span
                    class="box-estatisticas space-estatisticas2">Compradores</span> <span
                    class="box-estatisticas">Lances</span>

                <div class="box-estatisticas-number">
                    <span class=" space-estatisticas-number"><?php echo (int) $lote->VISITAS; ?></span>
                    <span class="space-estatisticas-number2 count-num-compradores-lote"><?php echo (int) $lote->COMPRADORES; ?></span>
                    <span class="count-num-lances-lote"><?php echo (int) $lote->LANCES; ?></span>
                </div>

            </div>

            <div class="clearfix"></div>

        </div>


    </div>
    <?php if (userData()->id < 1): ?>      
        <p class="text-final-painel-lance">Para efetuar seu lance, faça o login
            e solicite sua habilitação.</p>
    <?php endif; ?>    
</div>
<!-- BOX -->
<script type="text/javascript"> var ID_LEILAO = <?php echo $lote->LEILAO_ID; ?>;</script>
<?php
add_js('plugins/frontend/jquery.mousewheel.min', 'footer', 11);
// jquery.jqzoom-core.js
add_js('plugins/frontend/jquery.jqzoom-core', 'footer', 11);
add_js('plugins/frontend/fancybox/jquery.fancybox', 'footer', 6);
add_js('plugins/frontend/fancybox/jquery.fancybox-buttons', 'footer', 9);
add_js('plugins/frontend/fancybox/jquery.fancybox-media', 'footer', 9);
add_js('plugins/frontend/fancybox/jquery.fancybox-thumbs', 'footer', 9);
add_js('plugins/frontend/jquery.maskMoney', 'footer', 9);
add_js('scripts/frontend/detail-lotes', 'footer', 15);
add_js('plugins/lancesOperations', 'footer', 9);

add_css('frontend/fancybox/jquery.fancybox', 'header', 13);
add_css('frontend/fancybox/helpers/jquery.fancybox-buttons', 'header', 14);
add_css('frontend/fancybox/helpers/jquery.fancybox-thumbs', 'header', 15);
add_css('frontend/jquery.jqzoom', 'footer', 16);

